﻿using Finance.API.Read.Application.Command.FinancialBookkeepingCommand;
using Finance.API.Read.Application.Command.FinancialCategoryCommand;
using Finance.API.Read.Application.Command.PayableManagementCommand;
using Finance.API.Read.Application.Command.ReceivablesManagementCommand;
using Finance.Domain;
using Finance.Dtos;
using Finance.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Text;

namespace Finance.API.Read.Controllers
{
    /// <summary>
    /// 财务数据
    /// </summary>
    //[Authorize]
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class FinancialCategoryController : ControllerBase
    {
        IMediator mediator; 
        ILogger<FinancialCategoryController> logger;

        public FinancialCategoryController(IMediator mediator, ILogger<FinancialCategoryController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }
        /// <summary>
        /// 财务数据财务类别的显示
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIPaging<FinancialCategory>> ShowFinancialCategoryCommand([FromQuery]ShowFinancialCategoryCommand request)
        {
            try
            {
               return mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("财务数据财务类别显示失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 下拉框
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<FinancialCategory>>> SelectFinancialCategoryCommand()
        {
           
            try
            {
                SelectFinancialCategoryCommand request=new SelectFinancialCategoryCommand();
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("财务数据财务类别下拉框" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 应付管理
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]

        public async Task<APIPaging<PayableManagementDto>> ShowPayableManagementCommand([FromQuery]ShowPayableManagementCommand request)
        {
          
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("应付管理显示失败" + ex.Message);
                throw;
            }
        }

        /// <summary>
        /// 应收管理
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIPaging<ReceivablesManagementDto>> ShowReceivablesManagementCommand([FromQuery] ShowReceivablesManagementCommand request)
        {
           
            try
            {

                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("应收管理显示失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 财务记账显示
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<FinancialBookkeepingDto>> ShowFinancialBookkeepingCommand([FromQuery]ShowFinancialBookkeepingCommand request)
        {
          
            try
            {
                return await mediator.Send(request);

            }
            catch (Exception ex)
            {
                logger.LogError("应收管理显示失败" + ex.Message);
                throw;
            }
        }



    }
}
